{{!-- START：打开顶级视图 --}}
{{~#eq appDEUIAction.frontProcessType 'TOP'}}
// 根据视图名称 获取视图详情
const view = App.getAppViewConfig()['{{appDEUIAction.frontPSAppView.codeName}}'];
if (!view) {
	App.getNotificationHelper().warning('', '目标视图不存在');
	return { ok: false, data: [] };
}
// 打开视图
App.getOpenViewHelper().openIndexViewTab(view, context, viewParams);
return await this.afterAction(context, viewParams, data, event, ability, actionModel);
{{/eq~}}
{{!-- END: 打开顶级视图 --}}
{{!-- START：打开视图或向导（模态） --}}
{{~#eq appDEUIAction.frontProcessType 'WIZARD'}}
// 根据视图名称 获取视图详情
const view = App.getAppViewConfig()['{{appDEUIAction.frontPSAppView.codeName}}'];
if (!view) {
	App.getNotificationHelper().warning('', '目标视图不存在');
	return { ok: false, data: [] };
}
// 打开视图
const actionResult = await App.getOpenViewHelper().openPage(view, context, viewParams);
if (actionResult && actionResult.ok) {
	return await this.afterAction(context, viewParams, data, event, ability, actionModel);
} else {
	return { ok: false, data: [] };
}
{{/eq~}}
{{!-- END: 打开视图或向导（模态） --}}
{{!-- START：打印 --}}
{{~#eq appDEUIAction.frontProcessType 'PRINT'}}
let requestUrl: string = '';
	{{#if appDEUIAction.psAppDEPrint}}
if (context && context['{{lowerCase appDEUIAction.psAppDataEntity.codeName}}']) {
	requestUrl += `/{{lowerCase (pluralize appDEUIAction.psAppDataEntity.codeName)}}/printdata/${context['{{lowerCase appDEUIAction.psAppDataEntity.codeName}}']}`;
	if (context.srfparentdename && context.srfparentkey) {
		requestUrl = `${srfpluralize(context.srfparentdename).toLowerCase()}/${context.srfparentkey}` + requestUrl;
	}
} else {
	App.getNotificationHelper().error('错误', '无数据主键');
}
requestUrl += '?srfprinttag={{appDEUIAction.psAppDEPrint.codeName}}';
try {
	const response = await Http.getHttp()({
		url: requestUrl,
		method: 'get',
		responseType: 'blob'
	});
	if (response && response.status &&  (response.status === 200) && response.data) {
		const link = window.URL.createObjectURL(response.data);
    window.open(link, '_blank');
		return await this.afterAction(context, viewParams, data, event, ability, actionModel);
	} else {
		App.getNotificationHelper().error('错误', '打印失败');
	}
} catch (error: any) {
	App.getNotificationHelper().error('错误', '打印失败');
}
return { ok: false, data: [] };
	{{else}}
App.getNotificationHelper().warning('', '无打印项');
return { ok: false, data: [] };
	{{/if}}
{{/eq~}}
{{!-- END: 打印 --}}
{{!-- START：数据导入 --}}
{{~#eq appDEUIAction.frontProcessType 'DATAIMP'}}
	{{#if appDEUIAction.psAppDEDataImport}}
const view = {
	codeName: 'AppDataUpload',
	caption: '数据导入',
	name: 'app-data-upload',
	width: 544,
	height: 368
}
if (!(context.srfparentdename && context.srfparentkey)) {
	if (context.srfparentdename) {
		delete context.srfparentdename;
	}
	if (context.srfparentkey) {
		delete context.srfparentkey;
	}
}
const actionResult: IUIActionResult = await App.getOpenViewHelper().openModal(view, context, Object.assign({
	importId: '{{appDEUIAction.psAppDEDataImport.codeName}}',
	serviceName: '{{appDEUIAction.psAppDataEntity.codeName}}',
	appDeLogicName: '{{appDEUIAction.psAppDataEntity.logicName}}'
}, viewParams));
if (actionResult.ok) {
	if (ability && (ability as unknown as IViewAbility).refresh instanceof Function) {
		(ability as unknown as IViewAbility).refresh(viewParams);
	}
	return await this.afterAction(context, viewParams, data, event, ability, actionModel);
} else {
	return { ok: false, data: [] };
}
	{{else}}
App.getNotificationHelper().warning('警告', '无数据导入项');
	{{/if}}
{{/eq~}}
{{!-- END: 数据导入 --}}
{{!-- START：数据导出 --}}
{{~#eq appDEUIAction.frontProcessType 'DATAEXP'}}
	{{#if appDEUIAction.psAppDEDataExport}}
let url: string = '/{{lowerCase (pluralize appDEUIAction.psAppDataEntity.codeName)}}/exportdata/fetchdefault';
if (context.srfparentdename && context.srfparentkey) {
	url = `/${srfpluralize(context.srfparentdename).toLowerCase()}/${context.srfparentkey}` + url;
}
url += '?srfexporttag={{appDEUIAction.psAppDEDataExport.codeName}}';
const params: IParam = { page: 0, size: {{#if appDEUIAction.psAppDEDataExport.maxRowCount}}{{appDEUIAction.psAppDEDataExport.maxRowCount}}{{else}}1000{{/if}} };
try {
	const response = await Http.getHttp()({
		url: url,
		method: 'post',
		data: params,
		responseType: 'blob'
	});
	if (!response || (response.status && response.status !== 200)) {
		return { ok: false, data: [] };
	}
	const fileName: string = decodeURIComponent('{{appDEUIAction.psAppDataEntity.logicName}}.xlsx');
	let blob = new Blob([response.data], { type: 'application/vnd.ms-excel' });
	let elink = document.createElement('a');
	elink.download = fileName;
	elink.style.display = 'none';
	elink.href = URL.createObjectURL(blob);
	document.body.appendChild(elink);
	elink.click();
	URL.revokeObjectURL(elink.href); // 释放URL 对象
	document.body.removeChild(elink);
	return await this.afterAction(context, viewParams, data, event, ability, actionModel);
} catch (error: any) {
	try {
		const reader = new FileReader();
		reader.readAsText(error.data, 'utf-8');
		reader.onload = (event: any) => {
			const message = JSON.parse(event.target.result)?.message;
			App.getNotificationHelper().error('错误', message ? message : '导出失败');
		}
	} catch (error) {
		App.getNotificationHelper().error('错误', '导出失败');
	}
	return { ok: false, data: [] };
}
	{{else}}
App.getNotificationHelper().warning('警告', '无数据导出项');
return { ok: false, data: [] };
	{{/if}}
{{/eq~}}
{{!-- END: 数据导出 --}}
{{!-- START：用户自定义 --}}
{{~#eq appDEUIAction.frontProcessType 'OTHER'}}
eval(`{{appDEUIAction.scriptCode}}`);
return await this.afterAction(context, viewParams, data, event, ability, actionModel);
{{/eq~}}
{{!-- END: 用户自定义 --}}
{{!-- START：打开HTML页面 --}}
{{~#eq appDEUIAction.frontProcessType 'OPENHTMLPAGE'}}
window.open(
	formatUrlString(
		'{{appDEUIAction.htmlPageUrl}}',
		context,
		viewParams,
		data && data.length ? data[0] : {}
	),
	'_blank'
);
return await this.afterAction(context, viewParams, data, event, ability, actionModel);
{{/eq~}}
{{!-- END: 打开HTML页面 --}}
